/*
day466 
2020.12.6 
*/
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    int deepestLeavesSum(TreeNode* root) 
	{
		vector<TreeNode *> vec;
		queue<TreeNode *> que;
		que.push(root);
		
		while(!que.empty())
		{	
			vec.erase(vec.begin(),vec.end());
			int size=que.size();
			for(int i=0;i<size;++i)
			{
				TreeNode *tem=que.front();
				que.pop();
				vec.push_back(tem);
				if(tem->left) que.push(tem->left);
				if(tem->right) que.push(tem->right);
			}
		}
		
		int res=0;
		for(int i=0;i<vec.size();++i)
		{
			res+=vec[i]->val;
		}
		return res;
    }
};

int main()
{
	return 0;
}
